import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { IsArray, IsDecimal, IsEnum, isNotEmpty, IsNotEmpty, IsNumber, IsOptional, IsString, Length, Max, ValidateNested } from "class-validator";
import { Msgs } from "@/common/type/msg";
import { BooleanType } from "@/common/type/enum";
import { Type } from "class-transformer";

export class SCodeDto {
    @IsString({
        message: 's_code.fld_eng错误'
    })
    @IsNotEmpty({
        message: 's_code.fld_eng不能未空'
    })
    fld_eng: string;
    @IsString({
        message: 's_code.fld_chi错误'
    })
    @IsNotEmpty({
        message: 's_code.fld_chi不能未空'
    })
    fld_chi: string;
    @IsString({
        message: 's_code.code错误'
    })
    @IsNotEmpty({
        message: 's_code.code不能未空'
    })
    code: string;
    /* @IsString({
        message: 's_code.name错误'
    })
    @IsNotEmpty({
        message: 's_code.name不能未空'
    }) */
    name: string;
}

export class CntrSizeDto {

    @IsString({
        message: Msgs.CntrSizCodInvalid
    })
    @IsNotEmpty({
        message: Msgs.CntrSizCodEmpty
    })
    @ApiProperty({description: '箱尺寸代码'})
    cntr_siz_cod: string;

    @IsOptional()
    @IsNumber()
    @Max(9.9)
    @ApiPropertyOptional({description: 'TEU'})
    cntr_teu?: number;

    @IsString()
    @IsOptional()
    @ApiProperty({ description: '备注'})
    remark: string;
}

export class CntrTypeDto {

    @IsString({
        message: Msgs.CntrTypCodInvalid
    })
    @IsNotEmpty({
        message: Msgs.CntrTypCodEmpty
    })
    @ApiProperty({description: '箱类型代码'})
    cntr_typ_cod: string;

    @IsString({
        message: Msgs.CntrTypNamInvalid
    })
    @IsNotEmpty({
        message: Msgs.CntrTypNamEmpty
    })
    @ApiProperty({description: '箱类型名称'})
    cntr_typ_nam_c: string;

    /* @IsString({
        message: Msgs.CntrTypPartIDInvalid
    }) */
    @IsEnum(BooleanType, {
        message: Msgs.CntrTypPartIDInvalid
    })
    @IsOptional()
    @ApiProperty({description: '箱组件标识'})
    part_id?: BooleanType;

    /* @IsString({
        message: Msgs.CntrTypReefIDInvalid
    }) */
    @IsEnum(BooleanType, {
        message: Msgs.CntrTypReefIDInvalid
    })
    @IsOptional()
    @ApiProperty({description: '冷藏箱标识'})
    reef_id?: BooleanType;

    @IsNumber({}, {
        message: Msgs.CntrTypStandHighInvalid
    })
    @IsOptional()
    @ApiProperty({description: '标准箱高'})
    stand_high?: number;

    @IsString()
    @IsOptional()
    @ApiProperty({ description: '用户备注'})
    remark?: string;
}

export class CyCfsDto {
    @IsString({
        message: Msgs.CyCfsNamInvalid
    })
    @IsNotEmpty({
        message: Msgs.CyCfsNamEmpty
    })
    cfs_nam_c: string;
    free_days: number;
    stack_rate: number;
    country: string;
    linkman: string;
    tel: string;
    address: string;
    email: string;
    // parentId: number;
}
export class CfsStorageDto {
    @IsNotEmpty({
        message: '站点不能为空'
    })
    cfs_cod: number;

    @IsNotEmpty({
        message: '尺寸不能为空'
    })
    cntr_siz_cod: string;

    /* @IsNotEmpty({
        message: '箱型不能为空'
    })
    cntr_typ_cod: string; */

    free_days: number;
    
    @IsNotEmpty({
        message: '费率不能为空'
    })
    rate: number;

    @IsNotEmpty({
        message: '货币不能为空'
    })
    currency_cod: string;
    
    remark: string;
}

export class CyCfsAreaDto {
    @IsNumber({}, {
        message: Msgs.CyCfsCodInvalid
    })
    @IsNotEmpty({
        message: Msgs.CyCfsCodEmpty,
    })
    @ApiProperty({ description: '站点ID'})
    cfs_cod: number;

    
    @IsString({
        message: Msgs.CyCfsAreaInvalid
    })
    @IsNotEmpty({
        message: Msgs.CyCfsAreaEmpty
    })
    @Length(1, 4, {
        message: '箱区长度不能超4位'
    })
    cy_area: string;
}

export class ClientDto {

    /* @IsString({
        message: Msgs.ClientCodInvalid
    })
    @IsNotEmpty({
        message: Msgs.ClientCodEmpty
    })
    @ApiProperty({description: '客户代码'})
    client_cod: string; */

    @IsString({
        message: Msgs.ClientNamInvalid
    })
    @IsNotEmpty({
        message: Msgs.ClientCodEmpty
    })
    @ApiProperty({description: '客户中文名称'})
    client_nam_c: string;

    @IsString({
        message: Msgs.ClientENamInvalid
    })
    @IsOptional()
    @ApiProperty({description: '客户英文名称'})
    client_nam_e: string;

    @IsString({
        message: Msgs.ClientNamInvalid
    })
    @IsOptional()
    @ApiProperty({description: '客户中文简称'})
    client_short_c: string;

    @IsString({
        message: Msgs.ClientENamInvalid
    })
    @IsOptional()
    @ApiProperty({description: '客户英文简称'})
    client_short_e: string;    

    @IsEnum(BooleanType, {
        message: '运输公司标识错误'
    })
    @IsOptional()
    @ApiProperty({description: '运输公司标识'})
    trans_corp_id: BooleanType;

    @IsEnum(BooleanType, {
        message: '供应商标识错误'
    })
    @IsOptional()
    @ApiProperty({description: '供应商标识'})
    provid_id: BooleanType;

    @IsEnum(BooleanType, {
        message: '箱主标识错误'
    })
    @IsOptional()
    @ApiProperty({description: '箱主标识'})
    cntr_owner_id: BooleanType;

    @IsEnum(BooleanType, {
        message: '修箱公司标识错误'
    })
    @IsOptional()
    @ApiProperty({description: '修箱公司标识'})
    repair_id: BooleanType;

    @IsEnum(BooleanType, {
        message: '客户标识错误'
    })
    @IsOptional()
    @ApiProperty({description: '客户标识'})
    custom_id: BooleanType;

    @IsEnum(BooleanType, {
        message: '场站标识错误'
    })
    @IsOptional()
    @ApiProperty({description: '场站标识'})
    cfs_id: BooleanType;

    
    @IsString()
    @IsOptional()
    email?: string;
    
    @IsString()
    @IsOptional()
    client_nam_index?: string;
    
    @IsArray()
    @ValidateNested({ each: true }) // 对数组中的每个元素应用验证
    @Type(() => ClientBankDto) // 使用class-transformer确保类型安全    
    banks: ClientBankDto[];


    @IsString()
    @IsOptional()
    @ApiProperty({ description: '备注'})
    remark?: string;
}

export class ClientBankDto {
    
    client_id: number;

    @IsEnum(BooleanType, {
        message: '默认账号标识错误' 
    })
    @IsOptional()
    @ApiProperty({description: '默认账号标识'})
    default_id: BooleanType;

    @IsString()
    @IsNotEmpty({
        message: '银行名称不能为空'
    })    
    bank_nam: string;

    @IsString()
    @IsNotEmpty({
        message: '银行账号不能为空'
    })
    bank_account: string;
    
    @IsString()
    @IsOptional()
    tax_no: string;
}

export class PlaceDto {

    @IsString({
        message: Msgs.PlacNamInvalid
    })
    @IsNotEmpty({
        message: Msgs.PlacNamEmpty
    })
    @ApiProperty({description: '地点名称'})
    plac_nam: string;

    @IsString({
        message: Msgs.PlacNamInvalid
    })
    @IsOptional()
    @ApiProperty({description: '地点简称'})
    plac_short: string;

    @IsDecimal({}, {
        message: Msgs.PlacDistinceInvalid
    })
    @IsOptional()
    @ApiProperty({description: '地点距离'})
    distince: number;
}

export class UserQueryCfgDto {

    @IsOptional()
    user_name?: string;

    @IsNotEmpty({
        message: 'table-id不能为空'
    })
    table_id: string;

    @IsNotEmpty({
        message: '查询项目名称不能为空'
    })
    item_name: string;

    @IsNotEmpty({
        message: '查询项目内容不能为空'
    })
    cfg_json: object;

    @IsOptional()
    remark?: string;
}

